package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembj;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembj.vo.DpItemBjPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembj.vo.DpItemBjRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembj.vo.DpItemBjSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dpitem.DpItemBjDO;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.module.erp.service.dpitem.DpItemBjService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - ERP北疆口岸制单货号详情")
@RestController
@RequestMapping("/erp/dp-item-bj")
@Validated
public class DpItemBjController {

    @Resource
    private DpItemBjService dpItemBjService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP北疆口岸制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:create')")
    public CommonResult<Long> createDpItemBj(@Valid @RequestBody DpItemBjSaveReqVO createReqVO) {
        return success(dpItemBjService.createDpItemBj(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP北疆口岸制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:update')")
    public CommonResult<Boolean> updateDpItemBj(@Valid @RequestBody DpItemBjSaveReqVO updateReqVO) {
        dpItemBjService.updateDpItemBj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP北疆口岸制单货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:delete')")
    public CommonResult<Boolean> deleteDpItemBj(@RequestParam("id") Long id) {
        dpItemBjService.deleteDpItemBj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP北疆口岸制单货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:query')")
    public CommonResult<DpItemBjRespVO> getDpItemBj(@RequestParam("id") Long id) {
        DpItemBjDO dpItemBj = dpItemBjService.getDpItemBj(id);
        return success(BeanUtils.toBean(dpItemBj, DpItemBjRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP北疆口岸制单货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:query')")
    public CommonResult<PageResult<DpItemBjRespVO>> getDpItemBjPage(@Valid DpItemBjPageReqVO pageReqVO) {
        PageResult<DpItemBjDO> pageResult = dpItemBjService.getDpItemBjPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpItemBjRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP北疆口岸制单货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bj:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpItemBjExcel(@Valid DpItemBjPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpItemBjDO> list = dpItemBjService.getDpItemBjPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP北疆口岸制单货号详情.xls", "数据", DpItemBjRespVO.class,
                        BeanUtils.toBean(list, DpItemBjRespVO.class));
    }

}